package org.zhang.core.track;

import java.util.Stack;

public class Span {
    public int value;
    public Span parentSpan;
    public Span childSpan;

    public Span(int value, Span parentSpan) {
        this.value = value;
        this.parentSpan = parentSpan;
    }

    public String toString() {
        Stack<Integer> stacks = new Stack<>();
        StringBuilder sb = new StringBuilder();
        stacks.push(value);
        Span currentSpan = parentSpan;
        while (currentSpan != null) {
            stacks.push(currentSpan.value);
            currentSpan = currentSpan.parentSpan;
        }

        while (!stacks.isEmpty()) {
            sb.append(stacks.pop()).append(".");
        }
        return sb.length() > 0 ? sb.substring(0, sb.length() - 1) : sb.toString();
    }
}
